import http from "../http.ts"
import {getUserId} from "../../store";

/**
 * 普通用户修改个人信息
 * @param data
 * @return {Promise<axios.AxiosResponse<any>>}
 */
export const putUserInfo = (data) => {
    return http.put("/userInfo/info", data, {
        msg: false,
        token:true,
        load:true
    })
}

/**
 * 修改头像
 * @param data FromData
 * @return {Promise<axios.AxiosResponse<any>>}
 */
export const putUserAvatar = (data) => {
    data.append("id", getUserId())
    return http.put("/userInfo/avatar", data, {
        msg: false,
        token:true,
        load:true
    })
}

/**
 * 信息编辑页获取小区区列表
 * @param data
 * @return {Promise<axios.AxiosResponse<any>>}
 */
export const getCommunityList = (data) => {
    if (data.page < 10) {
        data.page = 10
    }
    return http.get(`/community/list/select?page=${data.page}&size=${data.size}`, {
        msg: false,
        token:true,
        load:true
    })
}


/**
 * 获取用户信息
 * @return {Promise<axios.AxiosResponse<any>>}
 */
export const getUserInfo = (data) => {
    return http.get("/userInfo/" + data, {
        msg: false,
        token:true,
        load:true
    })
}

export const getHomeUserInfo = () => {
    return http.get("/userInfo/home/" + getUserId(), {
        msg: false,
        token:true,
        load:true
    })
}

/**
 * 获取用户头像
 * @return {Promise<axios.AxiosResponse<any>>}
 */
export const getUserAvatar = () => {
    let userId = getUserId();

    return http.get("/userInfo/avatar/" + userId, {
        msg: false,
        token:true,
        load:true
    })
}